﻿using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Swashbuckle.AspNetCore.Annotations;

namespace Journeo_backend.Controllers
{
    [Route("api/[controller]")]
    [ApiController]
    [AllowAnonymous]
    public class TravelPlanController : ControllerBase
    {
        private readonly ITravelPlanService _travelPlanService;

        public TravelPlanController(ITravelPlanService travelPlanService)
        {
            _travelPlanService = travelPlanService;
        }

        [HttpPost("create")]
        [SwaggerOperation(Summary = "创建旅行计划", Description = "创建旅行计划")]
        [SwaggerResponse(200, "创建成功", typeof(Response<TravelPlan>))]
        [SwaggerResponse(400, "创建失败")]
        public async Task<IActionResult> CreateTravelPlan(TravelPlanDTO travelPlanDTO)
        {
            var response = await _travelPlanService.CreateTravelPlan(travelPlanDTO);
            return Ok(response);
        }

        [HttpPut("update")]
        [SwaggerOperation(Summary = "更新旅行计划", Description = "更新旅行计划")]
        [SwaggerResponse(200, "更新成功", typeof(Response<TravelPlan>))]
        [SwaggerResponse(400, "更新失败")]
        public async Task<IActionResult> UpdateTravelPlan(long planId, TravelPlanDTO travelPlanDTO)
        {
            var response = await _travelPlanService.UpdateTravelPlan(planId, travelPlanDTO);
            return Ok(response);
        }

        [HttpDelete("delete/{planId}")]
        [SwaggerOperation(Summary = "根据Id删除旅行计划", Description = "根据旅行计划的Id删除旅行计划")]
        [SwaggerResponse(200, "删除成功", typeof(Response<string>))]
        [SwaggerResponse(400, "删除失败")]
        public async Task<IActionResult> DeleteTravelPlan(long planId)
        {
            var response = await _travelPlanService.DeleteTravelPlan(planId);
            return Ok(response);
        }

        [HttpGet("detail/{planId}")]
        [SwaggerOperation(Summary = "根据Id获取旅行计划详情", Description = "根据Id获取旅行计划详情")]
        [SwaggerResponse(200, "获取成功", typeof(Response<TravelPlan>))]
        [SwaggerResponse(400, "获取失败")]
        public async Task<IActionResult> GetTravelPlanDetail(long planId)
        {
            var response = await _travelPlanService.GetTravelPlan(planId);
            return Ok(response);
        }

        [HttpGet("user/{userId}")]
        [SwaggerOperation(Summary = "根据用户获取旅行计划", Description = "根据用户获取旅行计划")]
        [SwaggerResponse(200, "获取成功", typeof(PageResponse<TravelPlan>))]
        [SwaggerResponse(400, "获取失败")]
        public async Task<IActionResult> GetTravelPlans(long userId, int pageNumber, int pageSize)
        {
            var response = await _travelPlanService.GetTravelPlans(userId, pageNumber, pageSize);
            return Ok(response);
        }


    }
}
